import { requestClient } from '#/api/request';


/**
 * 计划排产
 */

//下载导入模版
export const getExportExcel = () => {
  return requestClient.get(`/api/product_plan/plan_model/Export`, {
    responseType: 'blob',
  });
};

// 导入
export const importProductplanExcel = (data) => {
  return requestClient.post(`/api/product_plan/importExcel`,
    data,
    {  headers: {
        'Content-Type': 'multipart/form-data',
      },}
  )
};


//获取销售订单
export const getSaleOrderApi = (params) => {
  return requestClient.get(`/product_plan_sale/sale_material`, { params });
};

//获取生产订单(及对应物料)列表
export const reqProductOrderList = (params) => {
  return requestClient.get("/product_plan_detail/getProductionPlanMaterialList", { params });
};

//获取车间列表
export const getGridApi = () => {
  return requestClient.get(`/api/grids/list`);
};
// 新增排产计划
export const saveProductionPlanApi = (data) => {
  return requestClient.post(`/product_plan`, data);
};
// 删除
export const deleteProductionPlanApi = (id) => {
  return requestClient.delete(`/product_plan/new/${id}`);
};



// 排产分页列表(按单)
export function getProductionPlans(params) {
  return requestClient.get(`/product_plan/pages`,{ params });
}
// 排产分页列表(按明细)
export function reqProductionPlansByDetail(params) {
  return requestClient.get(`/product_plan_detail/list`,{ params })
}



// 编辑排产
export const updateProductionPlanApi = (data) => {
  return requestClient.put(`/product_plan`, data);
};
// 获取排产详情
export const getProductionPlanDetailApi = (params) => {
  return requestClient.get(`/product_plan`, { params });
};
// 导出排产
export const getProductionPlanExport = () => {
  return requestClient.get(`/product_plan/exportExcel`, {
    responseType: 'blob',
  });
};

// 获取物料
export const listMaterialsApi = (params) => {
  return requestClient.get(`/product_plan_material/list`, { params });
};
// 获取库存
export const getStockApi = (params) => {
  return requestClient.get(`/product_plan_material/bom`, { params });
};









/*
 * 车间排产
 */

//查询车间排产接口
export const reqWorkshopScheduleLing = (params) => {
  return requestClient.get(`/workShopPlan/pages`,{params});
};

//保存或更新车间排产接口
export const reqSaveOrUpdateWorkshopPlan = (data) => {
  return requestClient.post(`/workShopPlan/saveOrUpdateAll`,data);
};

//获取工单号
export const reqWorkOrder = () => {
  return requestClient.get(`/workShopPlan/seWorkOrderCode`);
};

//通过物料获取工艺跟对应工序列表
export const reqWorkmanshipListByMaterial = (params) => {
  return requestClient.get(`/workShopPlan/getCraftByMaterialCode`,{ params });
};

//通过工艺id获取工艺工序列表
export const reqProcessListByWorkmanshipId = (params) => {
  return requestClient.get(`/api/craft/getProcedures`,{params});
};

//获取线体/产线列表
export const reqLineList = () => {
  return requestClient.get(`/api/production_line/all_list`);
};
//通过车间获取线产线列表
export const reqLineListByGridId = (params) => {
  return requestClient.get(`/basic_data/production-lines`,{ params });
};

//通过车间和产线获取拼板条数和拼板码数
export const reqLayoutMetersAndLayoutStripCount = (params) => {
  return requestClient.get(`/basic_data`,{ params });
};

//通过车间id获取班组列表
export const reqTeamList = (params) => {
  return requestClient.get(`/workShopPlan/getTeamList`,{ params });
};



/**
 * 产线排产
 */
//获取产线排产列表数据
export const reqLineSchedulingList = (params) => {
  return requestClient.get("/line_scheduling/pages",{ params });
};

//通过id获取产线排产数据
export const reqLineSchedulingById = (id) => {
  return requestClient.get(`/line_scheduling/${id}`);
};

//获取产线排产明细数据
export const reqLineSchedulingListDetail = (params) => {
  return requestClient.get("/line_scheduling/list",{ params });
};

//保存一条产线排产数据
export const reqSaveLineScheduling = (data) => {
  return requestClient.post(`/line_scheduling`,data);
};

//更新一条产线排产数据
export const reqUpdateLineScheduling = (data) => {
  return requestClient.put(`/line_scheduling`,data);
};

//删除一条产线排产数据
export const reqDeleteLineScheduling = (id) => {
  return requestClient.delete(`/line_scheduling/${id}`);
};


//获取生产订单
export const reqProductOrders = (params) => {
  return requestClient.get(`/line_scheduling/getProductionPlanMaterialList`,{ params });
};

//通过车间获取产线列表
export const reqLineListByGrid = (params) => {
  return requestClient.get(`/line_scheduling/line_list`,{ params });
};

//通过车间获取工艺路线
export const reqCraftListByGrid = (params) => {
  return requestClient.get(`/line_scheduling/craft_route`,{ params });
};




/**
 * 编码规则
 */
export const reqCodingRules = (params) => {
  return requestClient.get(`/omTagCodeRules/pages`,{ params });
};

//保存一条编码规则
export const reqSaveCodingRules = (data) => {
  return requestClient.post(`/omTagCodeRules`,data);
};

//更新一条编码规则
export const reqUpdateCodingRules = (data) => {
  return requestClient.put(`/omTagCodeRules`,data);
};

//删除一条编码规则
export const reqDeleteCodingRules = (data) => {
  return requestClient.delete(`/omTagCodeRules/${data.id}`);
};



/**
 * 包装层级定义管理
 */
export const reqPackagingLevelList = (params) => {
  return requestClient.get(`/omPackageHierarchys/pages`,{ params });
};

//保存一条包装层级定义
export const reqSavePackagingLevel = (data) => {
  return requestClient.post(`/omPackageHierarchys`,data);
};

//更新一条包装层级定义
export const reqUpdatePackagingLevel = (data) => {
  return requestClient.put(`/omPackageHierarchys`,data);
};

//删除一条包装层级定义
export const reqDeletePackagingLevel = (data) => {
  return requestClient.delete(`/omPackageHierarchys/${data.id}`);
};

